﻿#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat src, dst;
void Threshold_Demo(int typeValue, void*)
{
//  cvtColor(src, dst, COLOR_BGR2GRAY);
  dst = src.clone();



//  Mat hline2 = getStructuringElement(MORPH_RECT, Size(2, typeValue), Point(-1, -1));
//  erode(dst, dst, hline2);
// dilate(dst, dst, hline2);

// equalizeHist(dst, dst);
    threshold(dst, dst, typeValue, 255, 0);
   Mat hline1 = getStructuringElement(MORPH_RECT, Size(7, 20), Point(-1, -1));
 //  dilate(dst, dst, hline1);
   erode(dst, dst, hline1);
  namedWindow("二值化图像",WINDOW_FREERATIO);
  imshow("二值化图像", dst);
}

int main(){
  src = imread("E:/workspace/qt/DaHeng/ng/add_dragonnew9.jpg");
  if (src.empty())
  {
    cout << "could not load image..." << endl;
    return -1;
  }
  cvtColor(src, src, COLOR_BGR2GRAY);
//  normalize(src,src,
//  equalizeHist(src, src);
  namedWindow("原图",WINDOW_FREERATIO);
  src =src(Rect(0,src.rows/2,src.cols,src.rows-src.rows/2));

  imshow("原图", src);
//    Mat kernel = (Mat_<char>(3, 3) << -1, 0, 1,
//                       -2, 0, 2,
//                       -1, 0, 1);


//      filter2D(src, src,-1, kernel);
  int a = 1;
  Threshold_Demo(10, 0);

  createTrackbar("Type Value", "二值化图像", &a, 255, Threshold_Demo);

  waitKey(0);
  return 0;
}
